﻿using System;
using System.Linq;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class AcademicOrganizationBLL : ComperioDataObject
    {

        /// <summary>
        /// This method insert an new AcademicOrganization in db
        /// </summary>
        /// <param name="person"></param>
        public void Create(AcademicOrganization academicOrganization)
        {
            DbContext.AcademicOrganizations.Add(academicOrganization);
            DbContext.SaveChanges();

        }

        public AcademicOrganization RetrieveAcademicOrganizationByID(Int32 academicOrganizationID)
        {
            return DbContext.AcademicOrganizations.Where(academicOrganization => academicOrganization.AcademicOrganizationID == academicOrganizationID).FirstOrDefault();

        }

        public IQueryable<AcademicOrganization> RetrieveAcademicOrganizations()
        {
            return DbContext.AcademicOrganizations;

        }

        /// <summary>
        /// This method delete an AcademicOrganization
        /// </summary>
        /// <param name="person"></param>
        public void Delete(AcademicOrganization academicOrganization)
        {
            DbContext.AcademicOrganizations.Remove(academicOrganization);
            DbContext.SaveChanges();

        }


        public IQueryable<Course> RetrieveCoursesByAcademicOrganization(Int32 academicOrganizationID)
        {
            var academicOrganization = DbContext.AcademicOrganizations.FirstOrDefault(ao => ao.AcademicOrganizationID == academicOrganizationID);
            return academicOrganization.Courses.AsQueryable();

        }

    }
}
